#!/bin/bash
#创建基本目录 root用户执行

error_exit(){
	echo "ERROR: $1"
	exit 1
}

cd /usr/local || error_exit "进入文件夹/usr/local失败"

if [ ! -e beetle ]
then
	mkdir beetle || error_exit "创建文件夹/usr/local/beetle失败"
	chown -R beetle.beetle beetle || error_exit "文件夹/usr/local/beetle赋权失败"
fi

if [ ! -e python ]
then
	mkdir python || error_exit "创建文件夹/usr/local/python失败"
	chown -R beetle.beetle python || error_exit "文件夹/usr/local/python赋权失败"
fi

if [ ! -e python_vm ]
then
	mkdir python_vm || error_exit "创建文件夹/usr/local/python_vm失败"
	chown -R beetle.beetle python_vm || error_exit "文件夹/usr/local/python_vm赋权失败"
fi

if [ ! -e nginx ]
then
	mkdir nginx || error_exit "创建文件夹/usr/local/nginx失败"
	chown -R beetle.beetle nginx || error_exit "文件夹/usr/local/nginx赋权失败"
fi



cd beetle || error_exit "进入文件夹/usr/local/beetle失败"

if [ ! -e code ]
then
	mkdir code || error_exit "创建文件夹/usr/local/beetle/code失败"
	chown -R beetle.beetle code || error_exit "文件夹/usr/local/beetle/code赋权失败"
fi

if [ ! -e config ]
then
	mkdir config || error_exit "创建文件夹/usr/local/beetle/config失败"
	chown -R beetle.beetle config || error_exit "文件夹/usr/local/beetle/config赋权失败"
fi

# if [ ! -e shell ]
# then
# 	mkdir shell || error_exit "创建文件夹/usr/local/beetle/shell失败"
# 	chown -R beetle.beetle shell || error_exit "文件夹/usr/local/beetle/shell赋权失败"
# fi

# if [ ! -e uwsgi ]
# then
# 	mkdir uwsgi || error_exit "创建文件夹/usr/local/beetle/uwsgi失败"
# 	chown -R beetle.beetle uwsgi || error_exit "文件夹/usr/local/beetle/uwsgi赋权失败"
# fi




cd /usr || error_exit "进入文件夹/usr失败"

if [ ! -e beetle ]
then
	mkdir beetle || error_exit "创建文件夹/usr/beetle失败"
	chown -R beetle.beetle beetle || error_exit "文件夹/usr/beetle赋权失败"
fi

cd /usr/beetle || error_exit "进入文件夹/usr/beetle失败"

if [ ! -e appbak ]
then
	mkdir appbak || error_exit "创建文件夹/usr/beetle/appbak失败"
	chown -R beetle.beetle appbak || error_exit "文件夹/usr/beetle/appbak赋权失败"
fi

if [ ! -e applogs ]
then
	mkdir applogs || error_exit "创建文件夹/usr/beetle/applogs失败"
	chown -R beetle.beetle applogs || error_exit "文件夹/usr/beetle/applogs赋权失败"
fi